﻿using Business.WPF;
using Presenters.WPF.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Presenters.WPF
{
    public class AsignSubjectToTeacherPresenter
    {
        public IAsignSubjectToTeacher view { get; set; }

        public AsignSubjectToTeacherPresenter(IAsignSubjectToTeacher view)
        {
            this.view = view;            
        }


        public void SearchSubjectInRealTime()
        {
            if (this.view.isSubjectSearchByName == true)
            {
                SearchSubjectByName();
            }

            if (this.view.isSubjectSearchByCode == true)
            {
                SearchSubjectByCode();
            }

            if (this.view.isSubjectSearchByAcronym == true)
            {
                SearchSubjectByAcronym();
            }
        }

        public void SearchTeacherInRealTime()
        {
            if (this.view.isTeacherSearchByName == true)
            {
                
            }

            if (this.view.isTeacherSearchByCode == true)
            {
                
            }

            if (this.view.isTeacherSearchByAcronym == true)
            {
                
            }
            this.view.listResultTeacher = DataAccess.TeacherDataAccess.GetAllTeachers();
        }

        public void SelectedSubjectOnCollection()
        {
            if (this.view.selectedSubject != null)
            {
                this.view.teacherTeachingLabel = "Dicta la materia: " + this.view.selectedSubject.nameSubject;
            }
        }

        public void SelectedTeacherOnCollection()
        {
            if (this.view.selectedTeacher != null)
            {
                this.view.teacherLabel = "Docente: " + this.view.selectedTeacher.Name;
            }
        }

        public void SearchSubjectByName()
        {
            try
            {
                SearchSubjectManager ssn = new SearchSubjectManager();
                this.view.listResultSubject = ssn.SearchByName(this.view.filterSubject, true);
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }

        public void SearchSubjectByCode()
        {
            try
            {
                SearchSubjectManager ssn = new SearchSubjectManager();
                this.view.listResultSubject = ssn.SearchByCode(this.view.filterSubject, true);
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }

        public void SearchSubjectByAcronym()
        {
            try
            {
                SearchSubjectManager ssn = new SearchSubjectManager();
                this.view.listResultSubject = ssn.SearchByAcronym(this.view.filterSubject, true);
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }

        public void SearchTeacher()
        {            //try
            //{
            //    NewSubjectManager ns = new NewSubjectManager();
            //    ns.newSubject(this.view.nameSubject, this.view.acronym, this.view.status, this.view.credits, this.view.description);
            //}
            //catch (ValidationException v_ex)
            //{
            //    this.view.message = v_ex.Message;
            //}
            //catch (BusinessException b_ex)
            //{
            //    this.view.message = b_ex.Message;
            //}
            //catch (Exception ex)
            //{
            //    this.view.message = "Error -> " + ex.Message;
            //}

        }
    }
}
